package com.wuye.repository;

import com.wuye.model.repair.Category;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by jiawenlong on 2016/7/26.
 */
public interface CategoryRepository extends PagingAndSortingRepository<Category, Long> {
    Category findById(long id);

    List<Category> findAll();
    @Query(nativeQuery = true, value = "SELECT * FROM Category WHERE parentId = ?1 Order By  id")
    List<Category> findByParentId(long parentId);


    @Query(nativeQuery = true, value = "SELECT c.id,c.name, c.parentId   FROM Category c WHERE c.parentId = ?1 GROUP BY c.id Order By  c.id")
    List<Object> findByParentIdInTable(long parentId);
}
